package com.controller;

import com.bug.mamage.WordInfoManage;
import com.model.WordInfo;
import com.model.neo4j.Movie;
import com.model.neo4j.Role;
import com.model.response.Response;
import com.pepository.neo4j.MovieRepository;
import com.pepository.neo4j.PersonRepository;
import com.pepository.neo4j.RoleRepository;
import com.service.Neo4jTestService;
import com.service.WordInfoService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.EncodeException;
import java.io.IOException;
import java.util.List;

@RestController
public class TestController {

    @Autowired
    private MovieRepository movieRepository;
    @Autowired
    private PersonRepository personRepository;
    @Autowired
    private RoleRepository roleRepository;
    @Autowired
    private WordInfoManage wordInfoManage;
    @Autowired
    private WordInfoService wordInfoService;
    @Autowired
    private Neo4jTestService neo4jTestService;


    @GetMapping("/create_movie")
    public Object createMovie(String movie, String personName, String mode, long pay){
        neo4jTestService.createMovie(movie, personName, mode, pay);
        return "ok";
    }

    @GetMapping("/get_movie_by_title")
    public Object getMovie(String title) {
        Movie movie = movieRepository.getGraphByTitle(title);
        return movie;
    }

    @GetMapping("/find_person_by_name")
    public Object findPersonByName() {
        return personRepository.findPeopleByName("王力宏");
    }

    @GetMapping("/find_all_role")
    public Object findAllRole() {
        List<Role> result = roleRepository.findAll();
        return result;
    }

    @GetMapping("/createWord")
    public Object createWord(String word) {
        if(Strings.isEmpty(word)) return "word is null";
        wordInfoManage.catchWord(word);
        return "server accept";
    }

    @PostMapping("socket/test")
    public void sendSocket(Long userId) throws IOException, EncodeException {
        WebSocket.sendMessage(userId, Response.success("test"));
    }

}
